from py_stealth import *

STORAGEBOX = 0x400E10C3  # 资源箱子
MATERIALS = [0x0EF3, 0x0F7B, 0x0F7A, 0x0F86]  # 资源
FINISHEDOBJECT = 0x1F4C  # 完成的成品
COUNT = 200  # 一次拿取资源的数量
WORKTOOLS = 0x0FBF  # 工作工具
TINKERSTOOLS = 0x1EBC  # 钳工工具
IRON = 0x1BF2  # 铁

def CheckTools():
    while GetGumpsCount() > 0:
        CloseSimpleGump(0)
    UseObject(STORAGEBOX)
    CheckLag(10000)
    Wait(2500)
    if FindType(WORKTOOLS, Backpack()) == 0:
        # 找铁
        if FindType(IRON, Backpack()) == 0:
            if FindType(IRON, STORAGEBOX) == 0:
                # 箱子里和包包里都没铁了
                Disconnect()
            elif FindQuantity() < COUNT:
                Disconnect()

    # 找工具


def CheckResource():
    while GetGumpsCount() > 0:
        CloseSimpleGump(0)
    UseObject(STORAGEBOX)
    CheckLag(10000)
    Wait(2500)
    for material in MATERIALS:
        FindType(material, Backpack())
        if FindQuantity() < 10:
            FindType(FINISHEDOBJECT, Backpack())
            MoveItem(FindItem(), FindQuantity(), STORAGEBOX, 0, 0, 0)
            CheckLag(10000)
            Wait(2500)
            FindType(material, STORAGEBOX)
            MoveItem(FindItem(), COUNT, Backpack(), 0, 0, 0)
            CheckLag(10000)
            Wait(2500)

def MakeLast():
    FindType(WORKTOOLS, Backpack())
    UseObject(FindItem())
    CheckLag(10000)
    NumGumpButton(0, 21)
    Wait(2000)

def Main():
    #while GetSkillValue('Alchemy') < 100:
    while Connected():
        CheckTools()
        CheckResource()
        MakeLast()
        #AddToSystemJournal(CharName() + ' has be done')


Main()
